<!--培训计划表 trainingSchedule-->
<template>
  <Layout>
    <Form ref="queryForm" :model="dataToQuery" :label-width="120">
      <Row v-show="!switchFlag" class="query-form">
        <Col span="8">
          <FormItem label='培训方式：'>
            <Select class="query-form-el" v-model="traMethods" multiple style="width: 100%;">
              <Option v-for="item in traMethodsList" :value="item.codingCodeId"
                      :key="item.codingCodeId">{{ item.codingName }}
              </Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label='培训类型：'>
            <Select class="query-form-el" multiple v-model="traTypes" style="width: 100%;">
              <Option v-for="item in traTypeList" :value="item.codingCodeId"
                      :key="item.codingCodeId">{{ item.codingName }}
              </Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <Button @click="switchQuery(true)" class="ivu-btn-switch" type="text">展开∨</Button>
          <Button @click="reseter" class="ivu-btn-reset">重置</Button>
          <Button type="primary" class="ivu-btn-query" icon="md-search" @click="queryDetail">查询</Button>
        </Col>
      </Row>
      <Row v-show="switchFlag" class="query-form">
        <Col span="8">
          <FormItem label='培训方式：'>
            <Select class="query-form-el" v-model="traMethods" multiple style="width: 100%;">
              <Option v-for="item in traMethodsList" :value="item.codingCodeId"
                      :key="item.codingCodeId">{{ item.codingName }}
              </Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label='培训类型：'>
            <Select class="query-form-el" multiple v-model="traTypes" style="width: 100%;">
              <Option v-for="item in traTypeList" :value="item.codingCodeId"
                      :key="item.codingCodeId">{{ item.codingName }}
              </Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="培训项目：">
            <Input type='text' v-model='dataToQuery.traName'></Input>
          </FormItem>
        </Col>
      </Row>
      <Row v-show="switchFlag" class="query-form">

        <Col span="8">
          <FormItem label="培训开始时间：">
            <DatePicker type="month" v-model="dataToQuery.traStartDate" split-panels placeholder="请选择"
                        style="width: 100%"></DatePicker>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="培训结束时间：">
            <DatePicker type="month" v-model="dataToQuery.traEndDate" split-panels placeholder="请选择"
                        style="width: 100%"></DatePicker>
          </FormItem>
        </Col>
        <Col span="8">
          <Button @click="switchQuery(false)" class="ivu-btn-switch" type="text">收起∧</Button>
          <Button @click="reseter" class="ivu-btn-reset">重置</Button>
          <Button class="ivu-btn-query" icon="md-search" @click="queryDetail">查询</Button>
        </Col>
      </Row>

      <Row class="query-form">
        <Col span="24">
          <Button size="large" class="ivu-btn-add" icon="md-add" @click="addInfo">新增</Button>
          <Button type="primary" class="ivu-btn-add" :loading="buttonLoading1" icon="md-cloud-download"
                  @click="downloadMod">导入模版下载
          </Button>
          <Button size="large" class="ivu-btn-add" icon="md-cloud-upload" @click="beachUpload">批量导入</Button>
          <Button size="large" class="ivu-btn-add" icon="md-cloud-upload"
                  @click="returnStatistic">返回
          </Button>
        </Col>
      </Row>
    </Form>
    <Table ref='table' :height="tableHeight" no-data-text="没有查询到相关数据!" @on-selection-change='getSelectRows'
           :loading='loading'
           border :columns="columns1" :data="detailDataTable">
    </Table>
    <Row style="margin-right:10px;">
      <Col span="24">
        <Page style="float: right" :total="detailPagedata.total" :page-size="detailPagedata.pageSize"
              @on-change="detailPageChange" @on-page-size-change="detailPageSizeChange"
              :page-size-opts="detailPageSizeArray" show-total show-sizer show-elevator/>
      </Col>
    </Row>
    <Modal :title="mode == 'view' ?'培训计划表详情':'培训计划表'" :transfer=false :mask-closable="false" v-model="dialogShow"
           v-if="dataToView && dialogShow" :width=800 :styles="{height:'559px'}" class-name='limit-height-dialog'>
      <Row>
        <Col span="24">
          <Form ref="dataToView" :class="mode === 'view'?'modal-view-detail':'modal-form'" :show-message="false"
                :model="dataToView" :rules="mode === 'view'?{} :ruleCustom"
                :label-position="mode === 'view'?'right':'top'" :label-width="mode === 'view'?160:null">
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="23">
                <FormItem label='企业名称：' prop='traOrgId'>
                  <div v-if="mode === 'view'">{{ dataToView.traOrgName }}</div>
                  <cascader-dom v-else ref='orgCascader' @setOrgInfo='setTraOrgId' @setOrgname="setTraOrgName"
                                :orgTree="true" :currentOrgId="dataToView.traOrgId"
                                :setCurrentName="{label:dataToView.traOrgName,value:dataToView.traOrgId}"></cascader-dom>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='培训类型：' prop='traTypeId'>
                  <div v-if="mode === 'view'">{{ dataToView.traTypeName }}</div>
                  <!--                                    <Input v-else class=''placeholder="请填写培训类型" type='text' v-model='dataToView.traTypeName'></Input>-->
                  <Select v-else v-model="dataToView.traTypeId" @on-change="selectTraType"
                          :label-in-value="true" placeholder="请选择培训类型">
                    <Option v-for="item in traTypeList" :value="item.codingCodeId"
                            :key="item.codingCodeId">{{ item.codingName }}
                    </Option>
                  </Select>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='培训项目：' prop='traName'>
                  <div v-if="mode === 'view'">{{ dataToView.traName }}</div>
                  <Input v-else class='' placeholder="请填写培训项目" type='text' v-model='dataToView.traName'></Input>
                </FormItem>
              </Col>
            </Row>

            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='培训主题：' prop='theme'>
                  <div v-if="mode === 'view'">{{ dataToView.themeName }}</div>
                  <!--                                    <Input v-else class=''placeholder="请填写培训方式" type='text' v-model='dataToView.traMethodsName'></Input>-->
                  <Select v-else v-model="dataToView.theme" placeholder="请选择培训主题">
                    <Option v-for="item in themeList" :value="item.codingCodeId"
                            :key="item.codingCodeId">{{ item.codingName }}
                    </Option>
                  </Select>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='培训方式：' prop='traMethodsId'>
                  <div v-if="mode === 'view'">{{ dataToView.traMethodsName }}</div>
                  <!--                                    <Input v-else class=''placeholder="请填写培训方式" type='text' v-model='dataToView.traMethodsName'></Input>-->
                  <Select v-else v-model="dataToView.traMethodsId" @on-change="selectTraMethods"
                          :label-in-value="true" placeholder="请选择培训类型">
                    <Option v-for="item in traMethodsList" :value="item.codingCodeId"
                            :key="item.codingCodeId">{{ item.codingName }}
                    </Option>
                  </Select>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='培训时间：' prop='traDate'>
                  <div v-if="mode === 'view'">{{ renderViewMonth(dataToView.traDate) }}</div>
                  <DatePicker v-else class="w" type="month" placeholder="请选择培训时间"
                              v-model='dataToView.traDate'></DatePicker>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='培训课时：' prop='traHours'>
                  <div v-if="mode === 'view'">{{ dataToView.traHours }}</div>
                  <InputNumber v-else class='w' placeholder="请填写培训课时" :min="0" type='text'
                               v-model='dataToView.traHours'></InputNumber>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='培训人数：' prop='traNum'>
                  <div v-if="mode === 'view'">{{ dataToView.traNum }}</div>
                  <InputNumber v-else class='w' placeholder="请填写培训人数" :min="0" type='text'
                               v-model='dataToView.traNum'></InputNumber>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='承办部门：' prop='traDepartmentName'>
                  <div v-if="mode === 'view'">{{ dataToView.traDepartmentName }}</div>
                  <Input v-else class='' placeholder="请填写承办部门" type='text'
                         v-model='dataToView.traDepartmentName'></Input>
                </FormItem>
              </Col>

            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='项目负责人：' prop='projectLeaderName'>
                  <div v-if="mode === 'view'">{{ dataToView.projectLeaderName }}</div>
                  <Input v-else class='' placeholder="请填写项目负责人" type='text'
                         v-model='dataToView.projectLeaderName'></Input>
                </FormItem>
              </Col>
              <Col span="11">
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg" v-if="mode === 'view'">
              <Col span="11">
                <FormItem label='创建人：' prop='userName'>
                  <div>{{ dataToView.userName }}</div>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='创建时间：' prop='createDate'>
                  <div>{{ renderViewDate(dataToView.createDate) }}</div>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="23">
                <FormItem label='培训对象：'>
                  <div v-if="mode === 'view'">{{ dataToView.traObjects }}</div>
                  <Input v-else class='' placeholder="请填写培训对象" type="textarea" :rows="4"
                         v-model='dataToView.traObjects'></Input>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="23">
                <FormItem label='培训内容：'>
                  <div v-if="mode === 'view'">{{ dataToView.traContent }}</div>
                  <Input v-else class='' placeholder="请填写培训内容" type="textarea" :rows="4"
                         v-model='dataToView.traContent'></Input>
                </FormItem>
              </Col>
            </Row>
          </Form>
        </Col>
      </Row>
      <div slot="footer">
        <Button v-if="mode != 'view'" type="primary" class='ivu-btn-save' @click="submit('dataToView')">确定</Button>
        <Button v-if="mode != 'view'" type="primary" class='ivu-btn-cancel' @click="handleCancel">取消</Button>
        <Button v-if="mode === 'view'" class='ivu-btn-save' @click="dialogShow=false">关闭</Button>
      </div>
    </Modal>
    <Modal :transfer=false v-model="model3" :width=700 title="年度培训计划导入" @on-cancel="cancelMap">
      <Form ref="map" :show-message="false" :model="map" :rules="mapRuleCustom" label-position="top">
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="23">
            <FormItem label='企业名称：' prop='companyId'>
              <cascader-dom ref='orgCascader1' @setOrgInfo='setCompanyId1' @setOrgname="setCompanyName1"
                            :orgTree="true" :currentOrgId="currentUser.companyId">
              </cascader-dom>
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="23">
            <FormItem label="年度培训计划Excel文件" prop="file">
              <div>
                <Upload ref="upload1"
                        :before-upload="handleUpload "
                        :format="['xlsx', 'xls']"
                        accept=".xlsx, .xls"
                        :max-size="10240"
                        type="drag"
                        :action="uploadUrl">
                  <div style="padding: 10px">
                    <Icon type="ios-cloud-upload" size="45" style="color: #3399ff"></Icon>
                    <p>点击将文件拖拽到这里上传</p>
                    <span style="font-size:8px;color: #797a64">仅支持上传单个excel </span>
                  </div>
                </Upload>
              </div>
              <div v-if="fileTrue">
                <a>{{ map.file.name }}</a>
                <Button type="text" icon="md-trash" @click="map.file = {},fileTrue = false"
                        style="margin-left: 5px;margin-bottom: 3px"/>
              </div>
            </FormItem>
          </Col>
        </Row>
      </Form>
      <div slot="footer">
        <Button type="primary" class='ivu-btn-save' :disabled="uploadDissabled" @click="submitFile('map')">确定</Button>
        <Button type="primary" class='ivu-btn-cancel' @click="cancelMap">取消</Button>
      </div>
    </Modal>
  </Layout>
</template>

<script>
import {Api} from '@/api/index.js'
import {sessionStorage} from '@/common/cacheUtils.js';
import {formatDate} from '@/tools/index'
import _deepclone from 'lodash/cloneDeep'
import pageCommonFunction from '@/components/pageCommonFunction.js'

var cascaderDom = () => import('@/components/cascader-dom.vue');
export default {
  components: {
    cascaderDom
  },
  data() {
    return {
      ...this.createCommonDataField(),
      currentUser: sessionStorage('userId').getObject('userId'),
      currentDetailVisible: false,
      switchFlag: false,
      detailDataTable: [],
      stdRankList: [],
      map: {},
      loading: false,
      traDate: ['', ''],
      buttonLoading1: false,
      fileTrue: false,
      traTypes: [],
      traMethods: [],
      detailPageSizeArray: [10, 20, 50],
      detailPagedata: {
        total: 0,
        pageSize: 10,
        currentPage: 1,
      },
      columns1: [
        {title: '序号', width: 80, fixed: 'left', align: 'center', render: this.indexColumnsRender},
        {key: 'traOrgName', title: '所属单位', minWidth: 150, align: 'center'},
        {key: 'traTypeName', title: '培训类型', minWidth: 150, align: 'center'},
        {key: 'themeName', title: '培训主题', minWidth: 150, align: 'center'},
        {key: 'traName', title: '培训项目', minWidth: 150, align: 'center', tooltip: true},
        {key: 'traContent', title: '培训内容', minWidth: 150, align: 'center', tooltip: true},
        {key: 'traObjects', title: '培训对象', minWidth: 150, align: 'center', tooltip: true},
        {key: 'traDate', title: '培训时间', minWidth: 150, align: 'center', render: this.renderCellMonth},
        {key: 'traNum', title: '培训人数', minWidth: 150, align: 'center'},
        {key: 'traHours', title: '培训课时', minWidth: 150, align: 'center'},
        {key: 'traMethodsName', title: '培训方式', minWidth: 150, align: 'center'},
        {key: 'traDepartmentName', title: '承办部门', minWidth: 150, align: 'center'},
        {key: 'projectLeaderName', title: '项目负责人', minWidth: 150, align: 'center'},
        this.getActionColumns()
      ],
      ruleCustom: {
        traOrgId: [{required: true, message: '请填写所属单位', trigger: 'change',}],
        traTypeId: [{required: true, message: '请填写培训类型', trigger: 'change',}],
        theme: [{required: true, message: '请选择培训主题', trigger: 'change',}],
        traName: [{required: true, message: '请填写培训项目', trigger: 'change',}],
        traContent: [{required: true, message: '请填写培训内容', trigger: 'change',}],
        traObjects: [{required: true, message: '请填写培训对象', trigger: 'change',}],
        traDate: [{required: true, message: '请填写培训时间', trigger: 'change', type: 'date'}],
        traNum: [{
          pattern: /^([0-9][0-9]*)+(.[0-9]{1,4})?$/,
          required: true,
          message: '请填写培训人数',
          trigger: 'change',
          type: 'number'
        }],
        traHours: [{
          pattern: /^([0-9][0-9]*)+(.[0-9]{1,4})?$/,
          required: true,
          message: '请填写培训课时',
          trigger: 'change',
          type: 'number'
        }],
        traMethodsId: [{required: true, message: '请填写培训方式', trigger: 'change',}],
        traDepartmentName: [{required: true, message: '请填写承办部门', trigger: 'change',}],
        projectLeaderName: [{required: true, message: '请填写项目负责人', trigger: 'change',}],

      },
      model3: false,
      mapRuleCustom: {
        companyId: [{required: true, message: ' ', trigger: 'change'}],
        file: [{
          validator: (rule, value, callback) => {
            if (this.map.file) {
              callback()
            } else {
              callback(' ')
            }
          },
          required: true,
          message: ' ',
          trigger: 'change'
        }]
      },
      tableHeight: 10,
      traTypeList: [],
      traMethodsList: [],
      themeList: [],
      uploadDissabled: false,
      currentCompanyId: this.$route.query.currentCompanyId,
      // api
      standardSelectModal: false,
      queryUrl: Api.queryTrainingSchedule,
      deleteUrl: Api.deleteTrainingSchedule,
      updateUrl: Api.updateTrainingSchedule,
      saveUrl: Api.saveTrainingSchedule,
      uploadUrl: Api.uploadTrainingSchedule,
    }
  },
  mounted() {
    this.dataToQuery = {};
    this.setTableHeight();
    this.$http.get(Api.queryCodeDetailBySortId + '/TRA-000002', {params: {}}).then((res) => {
      this.traMethodsList = res.data.data;
    });
    this.$http.get(Api.queryCodeDetailBySortId + '/TRA-000001', {params: {}}).then((res) => {
      this.traTypeList = res.data.data;
    });
    this.$http.get(Api.queryCodeDetailBySortId + '/TRA-000006', {params: {}}).then((res) => {
      this.themeList = res.data.data;
    });
    this.queryDetail();
  },
  methods: {
    ...pageCommonFunction,
    setTraOrgId(data) {
      if (data && data instanceof Array && data.length > 0) {
        this.$set(this.dataToView, 'traOrgId', data[data.length - 1])

      }
    },
    setTraOrgName(data) {
      if (data) {
        this.dataToView.traOrgName = data;
        this.$refs.dialogForm.validateField('traOrgName')
      }
    },
    setOrgId1(data) {
      // this.dataToQuery.traOrgId = data[data.length - 1];
    },
    setOrgName1(data) {
      this.dataToQuery.traOrgId = data
    },
    detailPageChange(pageNum) {
      this.detailPagedata.currentPage = pageNum;
      this.queryDetail();
    },
    detailPageSizeChange(pageSize) {
      this.detailPagedata.pageSize = pageSize;
      this.queryDetail();
    },
    selectTraType(item) {
      this.dataToView.traTypeName = item.label;
      this.dataToView.traTypeId = item.value;
    },

    queryDetail() {
      this.loading = true;
      let data = {
        currentPage: this.detailPagedata.currentPage,
        size: this.detailPagedata.pageSize,
      }
      this.dataToQuery.traTypeId = "";
      this.dataToQuery.traMethodsId = "";
      this.dataToQuery.traOrgId = this.currentCompanyId;
      this.traTypes.forEach(item => {
        this.dataToQuery.traTypeId += item + ","
      });
      this.traMethods.forEach(item => {
        this.dataToQuery.traMethodsId += item + ","
      });
      if (this.dataToQuery.traStartDate != "" && this.dataToQuery.traStartDate != undefined) {
        this.dataToQuery.traStartDate = formatDate(new Date(this.dataToQuery.traStartDate), 'yyyy-MM') + "-01 00:00:00";
      }
      if (this.dataToQuery.traEndDate != "" && this.dataToQuery.traEndDate != undefined) {
        this.dataToQuery.traEndDate = formatDate(new Date(this.dataToQuery.traEndDate), 'yyyy-MM') + "-31 23:59:59";
      }
      data = Object.assign(data, JSON.parse(JSON.stringify(this.dataToQuery)));
      let url = Api.queryTrainingScheduleByCompanyId;
      this.$http.get(url + "/" + this.currentCompanyId, {params: data}).then((res) => {
        this.detailDataTable = res.data.data.data;
        this.detailPagedata.total = res.data.data.totalSize;
        this.loading = false;
      }).catch(e => {
        this.$Message.error("数据获取失败")
      })
    },
    handleUpload(file) {
      this.map.file = file;
      this.fileTrue = true
      return false;
    },
    downloadMod() {
      this.buttonLoading1 = true
      let link = document.createElement('a');
      link.style.display = 'none';
      link.href = Api.downloadTrainingScheduleMod
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link)
      this.buttonLoading1 = false
    },
    cancelMap() {
      this.model3 = false
      this.fileTrue = false
      this.map = {}
      this.$refs.orgCascader1.resetCurrentOrg();
    },
    selectTraMethods(item) {
      this.dataToView.traMethodsName = item.label;
      this.dataToView.traMethodsId = item.value;
    },
    deleteDetail(id) {
      let _this = this;
      this.$Modal.confirm({
        title: '提示',
        content: '<p>确认删除此行数据？</p>',
        onOk: () => {
          let url = this.deleteUrl;
          this.$http.delete(url + '/' + id, {params: {}}).then((res) => {
            if (res.data.status === 200) {
              this.$Message.success('删除成功');
              if (_this.deleteDataToView instanceof Function) {
                _this.deleteDataToView()
              }
              this.queryDetail()
            } else if (res.data.status === 201) {
              this.$Message.error(res.data.msg);
            }
          }).catch(e => {
            this.$Message.error('删除失败' + e);
          })
        },
        onCancel: () => {
        }
      });
    },
    deleteData(params) {
      this.deleteDetail(params.row.id)
    },
    switchQuery(flag) {
      this.switchFlag = flag;
      if (!this.switchFlag) {
        this.tableHeight = this.tableHeight + 75;
      } else {
        this.tableHeight = this.tableHeight - 75;
      }
    },
    query() {
      this.dataToQuery.traTypeId = "";
      this.dataToQuery.traMethodsId = "";
      this.pagedata.currentPage = 1;
      this.pagedata.pageSize = 10;
      this.traTypes.forEach(item => {
        this.dataToQuery.traTypeId += item + ","
      });
      this.traMethods.forEach(item => {
        this.dataToQuery.traMethodsId += item + ","
      });
      if (this.dataToQuery.traStartDate != "" && this.dataToQuery.traStartDate != undefined) {
        this.dataToQuery.traStartDate = formatDate(new Date(this.dataToQuery.traStartDate), 'yyyy-MM') + "-01 00:00:00";
      }
      if (this.dataToQuery.traEndDate != "" && this.dataToQuery.traEndDate != undefined) {
        this.dataToQuery.traEndDate = formatDate(new Date(this.dataToQuery.traEndDate), 'yyyy-MM') + "-31 23:59:59";
      }
      this.query1()
    },
    submitFile(map) {
      this.$refs[map].validate((valid) => {
        if (valid) {
          this.uploadDissabled = true
          let formData = new FormData();
          formData.append("file", this.map.file);
          this.$http.post(this.uploadUrl + this.map.companyId, formData).then((res) => {
            this.uploadDissabled = false
            if (res.data.status == "200") {
              this.$Message.success("导入成功");
              this.queryDetail()
            } else {
              this.$Message.error(res.data.msg);
            }
            this.map = {}
            this.fileTrue = false
            this.model3 = false
          }).catch(e => {
            console.log(e);
            this.model3 = false
            this.map = {}
            this.uploadDissabled = false
            this.$Message.error("导入失败！请检查导入文档的格式是否正确");
          })
        } else {
          this.$Message.error('请填报完整!');
        }
      })

    },
    setCompanyId1(data) {
      if (data && data instanceof Array && data.length > 0) {
        this.$set(this.map, 'companyId', data[data.length - 1])
        // if(this.$refs.dialogForm) this.$refs.dialogForm.validateField('companyId')
      }
    },
    setCompanyName1(data) {
      if (data) {
        this.map.companyName = data;
        // this.$refs.dialogForm1.validateField('companyId')
      }
    },
    returnStatistic() {
      this.loading = false;
      this.$router.push({path: '/trainingScheduleStat'})
    },
    beachUpload() {
      this.model3 = true
      this.fileTrue = false
      this.map = {}
      this.$refs.orgCascader1.resetCurrentOrg();
    },
    selectSafeLevel(row) {
      this.dataToView.safeLevelId = row.value;
      this.dataToView.safeLevel = row.label;
    },
    selectstdRank(stdRank) {
      this.dataToView.safeRankId = stdRank.value;
      this.dataToView.safeRank = stdRank.label;
    },
    selectstdIndustry(row) {
      this.dataToView.industryId = row.value;
      this.dataToView.industry = row.label;
    },
    submitBase(name, dateToSubmit) {
      if (this.pageStatus.sending) return
      this.$refs[name].validate((valid) => {
        if (valid) {
          this.$Modal.confirm({
            title: '提示',
            content: '<p>是否要提交？</p>',
            onOk: () => {
              if (dateToSubmit === undefined) {
                dateToSubmit = _deepclone(this.dataToView)
              }
              let url = this.mode === 'add' ? this.saveUrl : this.updateUrl;
              // 月份转为日期
              if (dateToSubmit.traDate) {
                dateToSubmit.traDate = formatDate(dateToSubmit.traDate, 'yyyy-MM-dd')
              }
              this.pageStatus.sending = true

              let successHandle = (res) => {
                if (res.data.status === 200) {
                  this.$Message.success(this.mode === 'add' ? '添加成功' : '修改成功');
                  this.dialogShow = false;
                  this.queryDetail()
                } else if (res.data.status === 201) {
                  this.$Message.error(res.data.msg);
                }
                this.pageStatus.sending = false
              }
              let failedHandle = e => {
                this.$Message.error(this.mode === 'add' ? '添加失败' : '修改失败')
                this.pageStatus.sending = false
              }
              if (this.mode === 'add') {
                this.$http.post(url, dateToSubmit).then(successHandle).catch(failedHandle)
              } else {
                this.$http.put(url, dateToSubmit).then(successHandle).catch(failedHandle)
              }
            },
            onCancel: () => {
            }
          });
        } else {
          this.$Message.error('请填报完整!');
        }
      })
    },
    submit(name) {
      this.submitBase(name);
    },
    createEmptyDataToAdd() {
      return {
        traOrgId: sessionStorage('userId').getObject('userId').companyId,
        traOrgName: sessionStorage('userId').getObject('userId').companyName,
        traNum: 0,
        traHours: 0
      }
    },
    reseter() {
      this.traTypes = [];
      this.traMethods = [];
      this.dataToQuery = {};
      this.pagedata.currentPage = 1;
      this.pagedata.pageSize = 10;
      this.detailPagedata.currentPage = 1;
      this.detailPagedata.pageSize = 10;
      this.queryDetail()
    },

  },
  watch: {},

}
</script>

<style lang='css' scoped>

</style>
